﻿using System;
using Microsoft.Reporting.WebForms;
using Pharmacy.Data;
using Pharmacy.Entities;
using Pharmacy.Settings.BusinessLayer;

public partial class Admin_PreviewPO : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string Id = Request.QueryString["PoId"].ToString();
            PreviewPo(Id);
        }
    }

    private void PreviewPo(string PoId)
    {
        Po po = DataRepository.PoProvider.GetByPoId(PoId);
        DataRepository.PoProvider.DeepLoad(po);
        TList<PoDetails> listpoDetail = DataRepository.PoDetailsProvider.GetByPoId(PoId);
        //DataRepository.GrnDetailsProvider.DeepLoad(grnDetail);
        //ServiceFacade.SettingsHelper.DnCompanyAddress = "167A Nam Kỳ Khởi Nghĩa St., Dist 3, HCMC, Tel:(84 8) 38230498";
        //ServiceFacade.SettingsHelper.DnBrandName = "UNITE FORCE PHARMA 1";
        //ServiceFacade.SettingsHelper.DnVoidTitleEng = "VOID DELIVERY NOTE";
        //ServiceFacade.SettingsHelper.DnVoidTitleVn = "(Hủy phiếu giao hàng)";
        DSPo.PoDataTable dtPo = new DSPo.PoDataTable();
        DSPo.PoRow dtPoRow = dtPo.NewPoRow();
        dtPoRow.PoId = PoId;
        //  dtPoRow.Podate = Po.PoDate;
        dtPoRow.Podate = DateTime.Now;
        dtPoRow.RequestBy = po.RequestBySource.Name;
        dtPoRow.DeliveryTo = po.DeliveryTo;
        dtPoRow.BrandName = ServiceFacade.SettingsHelper.DnBrandName;
        dtPoRow.CompanyAddress = ServiceFacade.SettingsHelper.DnCompanyAddress;
        dtPo.AddPoRow(dtPoRow);

        DSPo.PoDetailsDataTable dtPoDetails = new DSPo.PoDetailsDataTable();
        DSPo.PoDetailsRow dtPoDetailsRow;
        foreach (PoDetails PoDetailItem in listpoDetail)
        {
            DataRepository.PoDetailsProvider.DeepLoad(PoDetailItem);
            dtPoDetailsRow = dtPoDetails.NewPoDetailsRow();
            dtPoDetailsRow.DrugId = PoDetailItem.DrugId;
            dtPoDetailsRow.DrugName = PoDetailItem.DrugIdSource.DrugName;
            dtPoDetailsRow.Unit = PoDetailItem.DrugIdSource.Unit;
            dtPoDetailsRow.Quantity = PoDetailItem.Quantity;
            dtPoDetailsRow.RemainQuantity = PoDetailItem.RemainQuantity;
            dtPoDetailsRow.Remark = PoDetailItem.Remark;
            dtPoDetails.AddPoDetailsRow(dtPoDetailsRow);

        }


        ReportViewer1.LocalReport.EnableExternalImages = true;
        ReportViewer1.LocalReport.DataSources.Clear();
        ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DSPo_Po", dtPo));
        ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DSPo_PoDetails", dtPoDetails));
        ReportViewer1.DataBind();
    }
}
